<!DOCTYPE HTML>
<html lang="en-US" >
    
    <head>
        
        <meta charset="UTF-8">
        <title>邮箱 | AKKA 2.3.6 Scala 文档</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 1.0.3">
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    
    
    
    <link rel="next" href="../chapter3/06_routing.html" />
    
    
    <link rel="prev" href="../chapter3/04_dispatchers.html" />
    

        
    </head>
    <body>
        
        
<link rel="stylesheet" href="../gitbook/style.css">


        
    <div class="book"  data-level="3.5" data-basepath=".." data-revision="1442802141200">
    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Type to search" class="form-control" />
    </div>
    <ul class="summary">
        
    	
    	
    	

        

        
    
        
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                        <i class="fa fa-check"></i>
                        
                         Introduction
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="1" data-path="chapter1/introduction.html">
            
                
                    <a href="../chapter1/introduction.html">
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                         引言
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="1.1" data-path="chapter1/01_what_is_akka.html">
            
                
                    <a href="../chapter1/01_what_is_akka.html">
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                         Akka是什么?
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="1.2" data-path="chapter1/02_why_akka.html">
            
                
                    <a href="../chapter1/02_why_akka.html">
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                         为什么使用Akka?
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="1.3" data-path="chapter1/03_getting_started.html">
            
                
                    <a href="../chapter1/03_getting_started.html">
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                         入门
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="1.4" data-path="chapter1/04_the_obligatory_hello_world.html">
            
                
                    <a href="../chapter1/04_the_obligatory_hello_world.html">
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                         必修的“Hello World”
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="1.5" data-path="chapter1/05_usecase_and_deployment_scenarios.html">
            
                
                    <a href="../chapter1/05_usecase_and_deployment_scenarios.html">
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                         用例和部署场景
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="1.6" data-path="chapter1/06_examples_of_usecases_for_akka.html">
            
                
                    <a href="../chapter1/06_examples_of_usecases_for_akka.html">
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                         Akka使用实例
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="2" data-path="chapter2/general.html">
            
                
                    <a href="../chapter2/general.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                         概述
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="2.1" data-path="chapter2/01_terminology_concepts.html">
            
                
                    <a href="../chapter2/01_terminology_concepts.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                         术语，概念
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="2.2" data-path="chapter2/02_actor_systems.html">
            
                
                    <a href="../chapter2/02_actor_systems.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                         Actor系统
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="2.3" data-path="chapter2/03_what_is_an_actor.html">
            
                
                    <a href="../chapter2/03_what_is_an_actor.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                         什么是Actor?
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="2.4" data-path="chapter2/04_supervision_and_monitoring.html">
            
                
                    <a href="../chapter2/04_supervision_and_monitoring.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                         监管与监控
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="2.5" data-path="chapter2/05_actor_references_paths_and_addresses.html">
            
                
                    <a href="../chapter2/05_actor_references_paths_and_addresses.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                         Actor引用, 路径与地址
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="2.6" data-path="chapter2/06_location_transparency.html">
            
                
                    <a href="../chapter2/06_location_transparency.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                         位置透明性
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="2.7" data-path="chapter2/07_akka_and_the_java_memory_model.html">
            
                
                    <a href="../chapter2/07_akka_and_the_java_memory_model.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                         Akka与Java内存模型
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="2.8" data-path="chapter2/08_message_delivery_reliability.html">
            
                
                    <a href="../chapter2/08_message_delivery_reliability.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                         消息发送语义
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="2.9" data-path="chapter2/09_configuration.html">
            
                
                    <a href="../chapter2/09_configuration.html">
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                         配置
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="3" data-path="chapter3/actors.html">
            
                
                    <a href="../chapter3/actors.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                         Actors
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="3.1" data-path="chapter3/01_actors.html">
            
                
                    <a href="../chapter3/01_actors.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                         Actors
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="3.2" data-path="chapter3/02_typed_actors.html">
            
                
                    <a href="../chapter3/02_typed_actors.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                         有类型Actor
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="3.3" data-path="chapter3/03_fault_tolerance.html">
            
                
                    <a href="../chapter3/03_fault_tolerance.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                         容错
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="3.3.1" data-path="chapter3/03-1_fault_tolerance_sample.html">
            
                
                    <a href="../chapter3/03-1_fault_tolerance_sample.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                         容错示例
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="3.4" data-path="chapter3/04_dispatchers.html">
            
                
                    <a href="../chapter3/04_dispatchers.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                         调度器
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter active" data-level="3.5" data-path="chapter3/05_mailboxes.html">
            
                
                    <a href="../chapter3/05_mailboxes.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                         邮箱
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="3.6" data-path="chapter3/06_routing.html">
            
                
                    <a href="../chapter3/06_routing.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                         路由
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="3.7" data-path="chapter3/07_fsm.html">
            
                
                    <a href="../chapter3/07_fsm.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                         有限状态机(FSM)
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="3.8" data-path="chapter3/08_persistence.html">
            
                
                    <a href="../chapter3/08_persistence.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                         持久化
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="3.9" data-path="chapter3/09_testing_actor_systems.html">
            
                
                    <a href="../chapter3/09_testing_actor_systems.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                         测试Actor系统
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="3.9.1" data-path="chapter3/09_1_testkit-example.html">
            
                
                    <a href="../chapter3/09_1_testkit-example.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.1.</b>
                        
                         TestKit实例
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="3.10" data-path="chapter3/10_actor_dsl.html">
            
                
                    <a href="../chapter3/10_actor_dsl.html">
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                         Actor DSL
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="4" data-path="chapter4/futures_and_agents.html">
            
                
                    <a href="../chapter4/futures_and_agents.html">
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                         Futures与Agents
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="4.1" data-path="chapter4/01_futures.html">
            
                
                    <a href="../chapter4/01_futures.html">
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                         Futures
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="4.2" data-path="chapter4/02_agents.html">
            
                
                    <a href="../chapter4/02_agents.html">
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                         Agents
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="5" data-path="chapter5/networking.html">
            
                
                    <a href="../chapter5/networking.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                         网络
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="5.1" data-path="chapter5/01_cluster_cpecification.html">
            
                
                    <a href="../chapter5/01_cluster_cpecification.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                         集群规格
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="5.2" data-path="chapter5/02_cluster_usage.html">
            
                
                    <a href="../chapter5/02_cluster_usage.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                         集群用法
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="5.3" data-path="chapter5/03_remoting.html">
            
                
                    <a href="../chapter5/03_remoting.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                         远程
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="5.4" data-path="chapter5/04_serialization.html">
            
                
                    <a href="../chapter5/04_serialization.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                         序列化
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="5.5" data-path="chapter5/05_io.html">
            
                
                    <a href="../chapter5/05_io.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                         I/O
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="5.6" data-path="chapter5/06_using_tcp.html">
            
                
                    <a href="../chapter5/06_using_tcp.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                         使用TCP
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="5.7" data-path="chapter5/07_using_udp.html">
            
                
                    <a href="../chapter5/07_using_udp.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                         使用UDP
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="5.8" data-path="chapter5/08_zeromq.html">
            
                
                    <a href="../chapter5/08_zeromq.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                         ZeroMQ
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="5.9" data-path="chapter5/09_camel.html">
            
                
                    <a href="../chapter5/09_camel.html">
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                         Camel
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="6" data-path="chapter6/utilities.html">
            
                
                    <a href="../chapter6/utilities.html">
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                         实用工具
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="6.1" data-path="chapter6/01_event_bus.html">
            
                
                    <a href="../chapter6/01_event_bus.html">
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                         事件总线
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="6.2" data-path="chapter6/02_logging.html">
            
                
                    <a href="../chapter6/02_logging.html">
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                         日志
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="6.3" data-path="chapter6/03_scheduler.html">
            
                
                    <a href="../chapter6/03_scheduler.html">
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                         调度器
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="6.4" data-path="chapter6/04_duration.html">
            
                
                    <a href="../chapter6/04_duration.html">
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                         Duration
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="6.5" data-path="chapter6/05_circuit_breaker.html">
            
                
                    <a href="../chapter6/05_circuit_breaker.html">
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                         线路断路器
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="6.6" data-path="chapter6/06_akka_extensions.html">
            
                
                    <a href="../chapter6/06_akka_extensions.html">
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                         Akka扩展
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="6.7" data-path="chapter6/07_microkernel.html">
            
                
                    <a href="../chapter6/07_microkernel.html">
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                         微内核
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="7" data-path="chapter7/howto_common_patterns.html">
            
                
                    <a href="../chapter7/howto_common_patterns.html">
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                         如何使用：常用模式
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="8" data-path="chapter8/experimental_modules.html">
            
                
                    <a href="../chapter8/experimental_modules.html">
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                         实验模块
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="8.1" data-path="chapter3/08_persistence.html">
            
                
                    <a href="../chapter3/08_persistence.html">
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                         持久化
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="8.2" data-path="chapter8/02_multi_node_testing.html">
            
                
                    <a href="../chapter8/02_multi_node_testing.html">
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                         多节点测试
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="8.3" data-path="chapter8/03_actors.html">
            
                
                    <a href="../chapter8/03_actors.html">
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                         Actors(使用Java的Lambda支持)
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="8.4" data-path="chapter8/04_fsm.html">
            
                
                    <a href="../chapter8/04_fsm.html">
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                         FSM(使用Java的Lambda支持)
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="8.5" data-path="chapter8/05_external_contributions.html">
            
                
                    <a href="../chapter8/05_external_contributions.html">
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                         外部贡献
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="9" data-path="chapter9/information_for_akka_developers.html">
            
                
                    <a href="../chapter9/information_for_akka_developers.html">
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                         Akka开发者信息
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="9.1" data-path="chapter9/01_building_akka.html">
            
                
                    <a href="../chapter9/01_building_akka.html">
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                         构建Akka
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="9.2" data-path="chapter9/02_multi_jvm_testing.html">
            
                
                    <a href="../chapter9/02_multi_jvm_testing.html">
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                         多JVM测试
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="9.3" data-path="chapter9/03_io_layer_design.html">
            
                
                    <a href="../chapter9/03_io_layer_design.html">
                        <i class="fa fa-check"></i>
                        
                            <b>9.3.</b>
                        
                         I/O层设计
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="9.4" data-path="chapter9/04_developer_guidelines.html">
            
                
                    <a href="../chapter9/04_developer_guidelines.html">
                        <i class="fa fa-check"></i>
                        
                            <b>9.4.</b>
                        
                         开发指南
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="9.5" data-path="chapter9/05_documentation_guidelines.html">
            
                
                    <a href="../chapter9/05_documentation_guidelines.html">
                        <i class="fa fa-check"></i>
                        
                            <b>9.5.</b>
                        
                         文档指南
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="9.6" data-path="chapter9/06_team.html">
            
                
                    <a href="../chapter9/06_team.html">
                        <i class="fa fa-check"></i>
                        
                            <b>9.6.</b>
                        
                         团队
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="10" data-path="chapter10/project_information.html">
            
                
                    <a href="../chapter10/project_information.html">
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                         工程信息
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="10.1" data-path="chapter10/01_migration_guides.html">
            
                
                    <a href="../chapter10/01_migration_guides.html">
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                         迁移指南
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="10.2" data-path="chapter10/02_issue_tracking.html">
            
                
                    <a href="../chapter10/02_issue_tracking.html">
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                         问题追踪
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="10.3" data-path="chapter10/03_licenses.html">
            
                
                    <a href="../chapter10/03_licenses.html">
                        <i class="fa fa-check"></i>
                        
                            <b>10.3.</b>
                        
                         许可证
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="10.4" data-path="chapter10/04_sponsors.html">
            
                
                    <a href="../chapter10/04_sponsors.html">
                        <i class="fa fa-check"></i>
                        
                            <b>10.4.</b>
                        
                         赞助商
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="10.5" data-path="chapter10/05_project.html">
            
                
                    <a href="../chapter10/05_project.html">
                        <i class="fa fa-check"></i>
                        
                            <b>10.5.</b>
                        
                         项目
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    
        
        <li class="chapter " data-level="11" data-path="chapter11/additional_information.html">
            
                
                    <a href="../chapter11/additional_information.html">
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                         附加信息
                    </a>
                
            
            
            <ul class="articles">
                
    
        
        <li class="chapter " data-level="11.1" data-path="chapter11/01_faq.html">
            
                
                    <a href="../chapter11/01_faq.html">
                        <i class="fa fa-check"></i>
                        
                            <b>11.1.</b>
                        
                         常见问题
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="11.2" data-path="chapter11/02_books.html">
            
                
                    <a href="../chapter11/02_books.html">
                        <i class="fa fa-check"></i>
                        
                            <b>11.2.</b>
                        
                         图书
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="11.3" data-path="chapter11/03_other_language_bindings.html">
            
                
                    <a href="../chapter11/03_other_language_bindings.html">
                        <i class="fa fa-check"></i>
                        
                            <b>11.3.</b>
                        
                         其他语言绑定
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="11.4" data-path="chapter11/04_akka_in_osgi.html">
            
                
                    <a href="../chapter11/04_akka_in_osgi.html">
                        <i class="fa fa-check"></i>
                        
                            <b>11.4.</b>
                        
                         Akka与OSGi
                    </a>
                
            
            
        </li>
    
        
        <li class="chapter " data-level="11.5" data-path="chapter11/05_incomplete_list_of_http_frameworks.html">
            
                
                    <a href="../chapter11/05_incomplete_list_of_http_frameworks.html">
                        <i class="fa fa-check"></i>
                        
                            <b>11.5.</b>
                        
                         部分HTTP框架名单
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="http://www.gitbook.io/" target="blank" class="gitbook-link">Published using GitBook</a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="Toggle search"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="Toggle font settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">Serif</button>
        <button type="button" data-font="1" class="button">Sans</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">White</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">Sepia</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">Night</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="Toggle share dropdown"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">Twitter</button>
                <button type="button" data-sharing="google-plus" class="button">Google</button>
                <button type="button" data-sharing="facebook" class="button">Facebook</button>
                <button type="button" data-sharing="weibo" class="button">Weibo</button>
                <button type="button" data-sharing="instapaper" class="button">Instapaper</button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Share on Google Plus"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Share on Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Share on Twitter"><i class="fa fa-twitter"></i></a>
    
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >AKKA 2.3.6 Scala 文档</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-gitbook_84">
                    
                        <h1 id="">邮箱</h1>
<p>一个Akka <code>Mailbox</code>保存发往某个Actor的消息。通常每个Actor都拥有自己的邮箱，但也有例外，例如使用<code>BalancingPool</code>的所有路由子(routee)共享同一个邮箱实例。</p>
<h3 id="">邮箱选择</h3>
<h5 id="actor">为actor指定一个消息队列类型</h5>
<p>为某个特定类型的actor指定一个特定类型的消息队列是有可能的，只要通过actor扩展<code>RequiresMessageQueue</code>参数化特质即可。下面是一个示例：</p>
<pre><code class="lang-scala"><span class="hljs-keyword">import</span> akka.dispatch.<span class="hljs-type">RequiresMessageQueue</span>
<span class="hljs-keyword">import</span> akka.dispatch.<span class="hljs-type">BoundedMessageQueueSemantics</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyBoundedActor</span> <span class="hljs-keyword"><span class="hljs-keyword">extends</span></span> <span class="hljs-title">MyActor</span>
</span>  <span class="hljs-keyword">with</span> <span class="hljs-type">RequiresMessageQueue</span>[<span class="hljs-type">BoundedMessageQueueSemantics</span>]
</code></pre>
<p><code>RequiresMessageQueue</code>特质的类型参数需要映射到配置中的邮箱，像这样：</p>
<pre><code>bounded-mailbox {
  mailbox-type = &quot;akka.dispatch.BoundedMailbox&quot;
  mailbox-capacity = 1000
  mailbox-push-timeout-time = 10s
}

akka.actor.mailbox.requirements {
  &quot;akka.dispatch.BoundedMessageQueueSemantics&quot; = bounded-mailbox
}
</code></pre><p>现在每当你创建一个类型为<code>MyBoundedActor</code>的actor时，它会尝试得到一个有界的邮箱。如果actor在部署中具有一个不同的邮箱配置——直接地，或是通过一个指定的邮箱类型的调度器——那么它将覆盖此映射。</p>
<blockquote>
<p>注意</p>
<p>为actor创建的邮箱队列类型，会和特质中要求的类型进行检查，如果队列没有实现要求的类型，则actor创建会失败。</p>
</blockquote>
<h5 id="">为调度器指定一个消息队列类型</h5>
<p>调度器也可能对actor使用的邮箱类型进行限制。一个例子是 BalancingDispatcher，它要求消息队列对多个并发的消费者是线程安全的。该约束是在配置的调度器一节中像下面这样设定：</p>
<pre><code>  my-dispatcher {
    mailbox-requirement = org.example.MyInterface
  }
</code></pre><p>给定的约束是要求指定的类或者接口，必须是消息队列的实现的超类。如果出现冲突——例如如果actor要求的邮箱类型不能满足要求——则actor创建会失败。</p>
<h5 id="">如何选择邮箱类型</h5>
<p>当一个actor创建时，<code>ActorRefProvider</code>首先确定将执行它的调度器。然后，邮箱确定如下：</p>
<ol>
<li>如果actor的部署配置节包含<code>mailbox</code>键，则其描述邮箱类型将被使用。</li>
<li>如果actor的<code>Props</code>包含邮箱选择——即它调用了<code>withMailbox</code>——则其描述邮箱类型将被使用。</li>
<li>如果调度器的配置节包含<code>mailbox-type</code>键，则该节内容将用于配置邮箱类型。</li>
<li>如果该actor需要邮箱类型，如上文所述，然后该约束的映射将用于确定使用的邮箱类型；如果不能满足调度器的约束——如果有的话——将继续替换尝试。</li>
<li>如果调度器需要一个邮箱类型，如上文所述，则该约束的映射将被用来确定要使用的邮箱类型。</li>
<li>将使用默认邮箱<code>akka.actor.default-mailbox</code>。</li>
</ol>
<h5 id="">默认邮箱</h5>
<p>当未如上所述，指定使用邮箱时，将使用默认邮箱。默认情况它是无界的邮箱，由<code>java.util.concurrent.ConcurrentLinkedQueue</code>实现。</p>
<p><code>SingleConsumerOnlyUnboundedMailbox</code>是一个更有效率的邮箱，而且它也可以用作默认邮箱，但它不能与 BalancingDispatcher一起使用。</p>
<p><code>SingleConsumerOnlyUnboundedMailbox</code>作为默认邮箱的配置：</p>
<pre><code>  akka.actor.default-mailbox {
    mailbox-type = &quot;akka.dispatch.SingleConsumerOnlyUnboundedMailbox&quot;
  }
</code></pre><h5 id="">哪项配置会传递给邮箱类型</h5>
<p>每个邮箱类型由扩展<code>MailboxType</code>并带两个构造函数参数的类实现：一个<code>ActorSystem.Settings</code>对象和一个<code>Config</code>对象。后者通过actor系统配置的指定配置节被计算出来，重写其指定邮箱类型的配置路径的<code>id</code>键，并添加一个到默认邮箱配置节的回退。</p>
<h3 id="">内置实现</h3>
<p>Akka自带有一些内置的邮箱实现：</p>
<ul>
<li><p>UnboundedMailbox</p>
<ul>
<li>默认邮箱</li>
<li>底层是一个<code>java.util.concurrent.ConcurrentLinkedQueue</code></li>
<li>阻塞: 否</li>
<li>有界: 否</li>
<li>配置名称：&quot;unbounded&quot; 或 &quot;akka.dispatch.UnboundedMailbox&quot;</li>
</ul>
</li>
<li><p>SingleConsumerOnlyUnboundedMailbox</p>
<ul>
<li>底层是一个非常高效的多生产者单消费者队列，不能被用于BalancingDispatcher</li>
<li>阻塞: 否</li>
<li>有界: 否</li>
<li>配置名称：&quot;akka.dispatch.SingleConsumerOnlyUnboundedMailbox&quot;</li>
</ul>
</li>
<li><p>BoundedMailbox</p>
<ul>
<li>底层是一个<code>java.util.concurrent.LinkedBlockingQueue</code></li>
<li>阻塞: 是</li>
<li>有界: 是</li>
<li>配置名称：&quot;bounded&quot; 或 &quot;akka.dispatch.BoundedMailbox&quot;</li>
</ul>
</li>
<li><p>UnboundedPriorityMailbox</p>
<ul>
<li>底层是一个<code>java.util.concurrent.PriorityBlockingQueue</code></li>
<li>阻塞: 是</li>
<li>有界: 否</li>
<li>配置名称：&quot;akka.dispatch.UnboundedPriorityMailbox&quot;</li>
</ul>
</li>
<li><p>BoundedPriorityMailbox</p>
<ul>
<li>底层是一个 <code>java.util.PriorityBlockingQueue</code>包装为<code>akka.util.BoundedBlockingQueue</code></li>
<li>阻塞: 是</li>
<li>有界: 是</li>
<li>配置名称：&quot;akka.dispatch.BoundedPriorityMailbox&quot;</li>
</ul>
</li>
</ul>
<h3 id="">邮箱配置示例</h3>
<p>如何创建一个PriorityMailbox：</p>
<pre><code class="lang-scala"><span class="hljs-keyword">import</span> akka.dispatch.<span class="hljs-type">PriorityGenerator</span>
<span class="hljs-keyword">import</span> akka.dispatch.<span class="hljs-type">UnboundedPriorityMailbox</span>
<span class="hljs-keyword">import</span> com.typesafe.config.<span class="hljs-type">Config</span>

<span class="hljs-comment">// We inherit, in this case, from UnboundedPriorityMailbox</span>
<span class="hljs-comment">// and seed it with the priority generator</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyPrioMailbox</span>(</span>settings: <span class="hljs-type">ActorSystem</span>.<span class="hljs-type">Settings</span>, config: <span class="hljs-type">Config</span>)
  <span class="hljs-keyword">extends</span> <span class="hljs-type">UnboundedPriorityMailbox</span>(
    <span class="hljs-comment">// Create a new PriorityGenerator, lower prio means more important</span>
    <span class="hljs-type">PriorityGenerator</span> {
      <span class="hljs-comment">// 'highpriority messages should be treated first if possible</span>
      <span class="hljs-keyword">case</span> <span class="hljs-symbol">'highpriority</span> =&gt; <span class="hljs-number">0</span>

      <span class="hljs-comment">// 'lowpriority messages should be treated last if possible</span>
      <span class="hljs-keyword">case</span> <span class="hljs-symbol">'lowpriority</span>  =&gt; <span class="hljs-number">2</span>

      <span class="hljs-comment">// PoisonPill when no other left</span>
      <span class="hljs-keyword">case</span> <span class="hljs-type">PoisonPill</span>    =&gt; <span class="hljs-number">3</span>

      <span class="hljs-comment">// We default to 1, which is in between high and low</span>
      <span class="hljs-keyword">case</span> otherwise     =&gt; <span class="hljs-number">1</span>
    })
</code></pre>
<p>并添加到配置文件:</p>
<pre><code>prio-dispatcher {
  mailbox-type = &quot;docs.dispatcher.DispatcherDocSpec$MyPrioMailbox&quot;
  //Other dispatcher configuration goes here
}
</code></pre><p>以下示例演示如何使用它:</p>
<pre><code class="lang-scala"><span class="hljs-comment">// We create a new Actor that just prints out what it processes</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Logger</span> <span class="hljs-keyword"><span class="hljs-keyword">extends</span></span> <span class="hljs-title">Actor</span> {</span>
  <span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title">log</span>:</span> <span class="hljs-type">LoggingAdapter</span> = <span class="hljs-type">Logging</span>(context.system, <span class="hljs-keyword">this</span>)

  self ! <span class="hljs-symbol">'lowpriority</span>
  self ! <span class="hljs-symbol">'lowpriority</span>
  self ! <span class="hljs-symbol">'highpriority</span>
  self ! <span class="hljs-symbol">'pigdog</span>
  self ! <span class="hljs-symbol">'pigdog2</span>
  self ! <span class="hljs-symbol">'pigdog3</span>
  self ! <span class="hljs-symbol">'highpriority</span>
  self ! <span class="hljs-type">PoisonPill</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">receive</span> =</span> {
    <span class="hljs-keyword">case</span> x =&gt; log.info(x.toString)
  }
}
<span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title">a</span> =</span> system.actorOf(<span class="hljs-type">Props</span>(classOf[<span class="hljs-type">Logger</span>], <span class="hljs-keyword">this</span>).withDispatcher(
  <span class="hljs-string">"prio-dispatcher"</span>))

<span class="hljs-comment">/*
 * Logs:
 * 'highpriority
 * 'highpriority
 * 'pigdog
 * 'pigdog2
 * 'pigdog3
 * 'lowpriority
 * 'lowpriority
 */</span>
</code></pre>
<p>也可以像这样直接配置邮箱类型：</p>
<pre><code>prio-mailbox {
  mailbox-type = &quot;docs.dispatcher.DispatcherDocSpec$MyPrioMailbox&quot;
  //Other mailbox configuration goes here
}

akka.actor.deployment {
  /priomailboxactor {
    mailbox = prio-mailbox
  }
}
</code></pre><p>然后可以在部署环境像这样使用它：</p>
<pre><code class="lang-scala"><span class="hljs-keyword">import</span> akka.actor.<span class="hljs-type">Props</span>
<span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title">myActor</span> =</span> context.actorOf(<span class="hljs-type">Props</span>[<span class="hljs-type">MyActor</span>], <span class="hljs-string">"priomailboxactor"</span>)
</code></pre>
<p>或像这样在代码中：</p>
<pre><code class="lang-scala"><span class="hljs-keyword">import</span> akka.actor.<span class="hljs-type">Props</span>
<span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title">myActor</span> =</span> context.actorOf(<span class="hljs-type">Props</span>[<span class="hljs-type">MyActor</span>].withMailbox(<span class="hljs-string">"prio-mailbox"</span>))
</code></pre>
<h3 id="">创建自己的邮箱类型</h3>
<p>例子比文字更有说服力：</p>
<pre><code class="lang-scala"><span class="hljs-keyword">import</span> akka.actor.<span class="hljs-type">ActorRef</span>
<span class="hljs-keyword">import</span> akka.actor.<span class="hljs-type">ActorSystem</span>
<span class="hljs-keyword">import</span> akka.dispatch.<span class="hljs-type">Envelope</span>
<span class="hljs-keyword">import</span> akka.dispatch.<span class="hljs-type">MailboxType</span>
<span class="hljs-keyword">import</span> akka.dispatch.<span class="hljs-type">MessageQueue</span>
<span class="hljs-keyword">import</span> akka.dispatch.<span class="hljs-type">ProducesMessageQueue</span>
<span class="hljs-keyword">import</span> com.typesafe.config.<span class="hljs-type">Config</span>
<span class="hljs-keyword">import</span> java.util.concurrent.<span class="hljs-type">ConcurrentLinkedQueue</span>
<span class="hljs-keyword">import</span> scala.<span class="hljs-type">Option</span>

<span class="hljs-comment">// Marker trait used for mailbox requirements mapping</span>
<span class="hljs-class"><span class="hljs-keyword">trait</span> <span class="hljs-title">MyUnboundedMessageQueueSemantics</span>
</span>
<span class="hljs-class"><span class="hljs-keyword">object</span> <span class="hljs-title">MyUnboundedMailbox</span> {</span>
  <span class="hljs-comment">// This is the MessageQueue implementation</span>
  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyMessageQueue</span> <span class="hljs-keyword"><span class="hljs-keyword">extends</span></span> <span class="hljs-title">MessageQueue</span>
</span>    <span class="hljs-keyword">with</span> <span class="hljs-type">MyUnboundedMessageQueueSemantics</span> {

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title">queue</span> =</span> <span class="hljs-keyword">new</span> <span class="hljs-type">ConcurrentLinkedQueue</span>[<span class="hljs-type">Envelope</span>]()

    <span class="hljs-comment">// these should be implemented; queue used as example</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">enqueue</span>(</span>receiver: <span class="hljs-type">ActorRef</span>, handle: <span class="hljs-type">Envelope</span>): <span class="hljs-type">Unit</span> =
      queue.offer(handle)
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">dequeue</span>(</span>): <span class="hljs-type">Envelope</span> = queue.poll()
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">numberOfMessages</span>:</span> <span class="hljs-type">Int</span> = queue.size
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hasMessages</span>:</span> <span class="hljs-type">Boolean</span> = !queue.isEmpty
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">cleanUp</span>(</span>owner: <span class="hljs-type">ActorRef</span>, deadLetters: <span class="hljs-type">MessageQueue</span>) {
      <span class="hljs-keyword">while</span> (hasMessages) {
        deadLetters.enqueue(owner, dequeue())
      }
    }
  }
}

<span class="hljs-comment">// This is the Mailbox implementation</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyUnboundedMailbox</span> <span class="hljs-keyword"><span class="hljs-keyword">extends</span></span> <span class="hljs-title">MailboxType</span>
</span>  <span class="hljs-keyword">with</span> <span class="hljs-type">ProducesMessageQueue</span>[<span class="hljs-type">MyUnboundedMailbox</span>.<span class="hljs-type">MyMessageQueue</span>] {

  <span class="hljs-keyword">import</span> <span class="hljs-type">MyUnboundedMailbox</span>._

  <span class="hljs-comment">// This constructor signature must exist, it will be called by Akka</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">this</span>(</span>settings: <span class="hljs-type">ActorSystem</span>.<span class="hljs-type">Settings</span>, config: <span class="hljs-type">Config</span>) = {
    <span class="hljs-comment">// put your initialization code here</span>
    <span class="hljs-keyword">this</span>()
  }

  <span class="hljs-comment">// The create method is called to create the MessageQueue</span>
  <span class="hljs-keyword">final</span> <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create</span>(</span>owner: <span class="hljs-type">Option</span>[<span class="hljs-type">ActorRef</span>],
                            system: <span class="hljs-type">Option</span>[<span class="hljs-type">ActorSystem</span>]): <span class="hljs-type">MessageQueue</span> =
    <span class="hljs-keyword">new</span> <span class="hljs-type">MyMessageQueue</span>()
}
</code></pre>
<p>然后在派发器配置中，或邮箱配置中以你定义的邮箱类型的全称作为“mailbox-type”的值。</p>
<blockquote>
<p>注意</p>
<p>一定要定义一个以<code>akka.actor.ActorSystem.Settings</code>和<code>com.typesafe.config.Config</code>为参数的构造函数，该构造函数将以反射的方式被调用来创建你的邮箱类型。第二个传入的配置参数是配置文件中使用这个邮箱类型的派发器或邮箱的描述；该邮箱类型会为每一个使用它的派发器或邮箱创建一个实例。</p>
</blockquote>
<p>此外可以作为派发器的约束这样使用邮箱：</p>
<pre><code>custom-dispatcher {
  mailbox-requirement =
  &quot;docs.dispatcher.MyUnboundedJMessageQueueSemantics&quot;
}

akka.actor.mailbox.requirements {
  &quot;docs.dispatcher.MyUnboundedJMessageQueueSemantics&quot; =
  custom-dispatcher-mailbox
}

custom-dispatcher-mailbox {
  mailbox-type = &quot;docs.dispatcher.MyUnboundedJMailbox&quot;
}
</code></pre><p>或通过在你的actor类上定义约束，像这样：</p>
<pre><code class="lang-scala"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MySpecialActor</span> <span class="hljs-keyword"><span class="hljs-keyword">extends</span></span> <span class="hljs-title">Actor</span>
</span>  <span class="hljs-keyword">with</span> <span class="hljs-type">RequiresMessageQueue</span>[<span class="hljs-type">MyUnboundedMessageQueueSemantics</span>] {
  <span class="hljs-comment">// ...</span>
}
</code></pre>
<h3 id="systemactorof"><code>system.actorOf</code>的特殊语义</h3>
<p>为了使<code>system.actorOf</code>同步和非阻塞，并且返回类型保持为<code>ActorRef</code>（并且保持返回的ref是完全函数式的语义），这种情况下会进行特殊处理。在幕后，一种空心的actor引用会被构造，然后发送到系统的监管者，该监管者实际创建actor和它的上下文，并把它们传到引用内部。直到这些发生以后，发送到该<code>ActorRef</code>的消息会被本地排队，而只有当填入真实信息后，它们才会被传入真实的邮箱，因此，</p>
<pre><code class="lang-scala"><span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title">props</span>:</span> <span class="hljs-type">Props</span> = ...
<span class="hljs-comment">// this actor uses MyCustomMailbox, which is assumed to be a singleton</span>
system.actorOf(props.withDispatcher(<span class="hljs-string">"myCustomMailbox"</span>)) ! <span class="hljs-string">"bang"</span>
assert(<span class="hljs-type">MyCustomMailbox</span>.instance.getLastEnqueuedMessage == <span class="hljs-string">"bang"</span>)
</code></pre>
<p>可能会失败；你将不得不留出一些时间来传递，然后重新尝试检查<code>TestKit.awaitCond</code>。</p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../chapter3/04_dispatchers.html" class="navigation navigation-prev " aria-label="Previous page: 调度器"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../chapter3/06_routing.html" class="navigation navigation-next " aria-label="Next page: 路由"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="https://cdn.mathjax.org/mathjax/2.4-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-mathjax/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
